﻿/**
 * ...
 * @author Sergey Mamyan
 */

package tx.squirrel.neko.core.handler;

import neko.Web;
import tx.squirrel.neko.admin.handler.AdminHandler;
import tx.squirrel.neko.core.model.Config;
import tx.squirrel.neko.core.model.Session;
import tx.squirrel.neko.core.model.User;
import tx.squirrel.neko.facebook.handler.FacebookHandler;
import tx.squirrel.neko.opensocial.handler.OpenSocialHandler;

class RootHandler extends BaseHandler {
	
	public function new() {
		super();
		Config.load();
        //logged("admin", 	handler(new AdminHandler()));
        free("facebook", 	handler(new FacebookHandler()));
        free("opensocial",	handler(new OpenSocialHandler()));
        //logged("logout", 	null, doLogout);
        //free("default",		null, doDefault);
		//free("login",		"login.mtt", doLogin);
	}
	/*
	public function doDefault() {
		if (isLogged()) {
			redirect("/admin");
		}else {
			redirect("/login");
		}
    }
	
	public function doLogin() {
		if (Web.getMethod() == "POST") {
			var params:Hash<String> = Web.getParams();
			var email:String = params.get("email");
			var password:String = params.get("password");
			var authUserList:List < User > = User.manager.search( { email:email } );
			var authUser:User = authUserList.first();
			if (authUser == null) {
				Session.writeLog("error", "Invalid email adress");
				redirect("/");
			}else if (authUser.password != password){
				Session.writeLog("error", "Invalid password");
				redirect("/");
			}else {
				Session.writeLog("info", "Welcome "+authUser.fullName);
				setUser(authUser.id);
				redirect("/");
			}
		} else {
			display();
		}
    }
	
	public function doLogout() {
		unsetUser();
		redirect("/");
    }
	*/
}